package org.cuasloi.rabbitmq.direct;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class DirectSpringRabbitListener {

    /* 使用注释方式配置绑定关系 */
    @RabbitListener(bindings = @QueueBinding(
            // 创建队列
            value = @Queue(name = "direct.queue1"),
            // 创建交换机
            exchange = @Exchange(name = "direct.exchange", type = ExchangeTypes.DIRECT),
            // 绑定路由key
            key = {"route1", "route2"}
    ))
    public void directQueueListener1(String msg) {
        System.out.println("Queue1接收到消息： " + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            // 创建队列
            value = @Queue(name = "direct.queue2"),
            // 创建交换机
            exchange = @Exchange(name = "direct.exchange", type = ExchangeTypes.DIRECT),
            // 绑定路由key
            key = {"route2", "route3"}
    ))
    public void directQueueListener2(String msg) {
        System.out.println("Queue2接收到消息： " + msg);
    }

}
